package com.erp.base.common.utils;

import java.io.Serializable;

public class OperationResult implements Serializable {
	private static final long serialVersionUID = 6327407759272273990L;
	public static final String SUCCESS="success";
	public static final String FAILURE="failure";
	public static final String SUCCESS_MESSAGE="成功";
	public static final String FAILURE_MESSAGE="失败";
	public static final Integer SUCCESS_CODE=200;
	public static final Integer FAILURE_CODE=444;
	/** 返回success或failure操作标识 */
	private String type;
	/** 返回200或其他错误码 */
	private Integer code;

	/** 国际化处理的返回JSON消息正文，一般用于提供failure错误消息 */
	private String message;

	/** 补充的业务数据 */
	private Object data;

	/** 标识redirect路径 */
	private String redirect;

	public OperationResult(String type, String message,int code) {
		this.type = type;
		this.message = message;
		this.code=code;
	}

	public OperationResult(String type, String message,int code, Object data) {
		this.type = type;
		this.message = message;
		this.code=code;
		this.data = data;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getRedirect() {
		return redirect;
	}

	public void setRedirect(String redirect) {
		this.redirect = redirect;
	}
	public static OperationResult buildSuccessResult() {
		return new OperationResult(SUCCESS, SUCCESS_MESSAGE,SUCCESS_CODE);
	}
	public static OperationResult buildSuccessResult(String message) {
		return new OperationResult(SUCCESS, message,SUCCESS_CODE);
	}
	public static OperationResult buildSuccessResult(Integer code) {
		return new OperationResult(SUCCESS, SUCCESS_MESSAGE,code);
	}
	public static OperationResult buildSuccessResult(Object data) {
		return new OperationResult(SUCCESS, SUCCESS_MESSAGE,SUCCESS_CODE, data);
	}
	public static OperationResult buildSuccessResult(String message,Object data) {
		return new OperationResult(SUCCESS, message,SUCCESS_CODE, data);
	}
	public static OperationResult buildSuccessResult(String message,Integer code,Object data) {
		return new OperationResult(SUCCESS, message,code, data);
	}
	
	public static OperationResult buildFailureResult() {
		return new OperationResult(FAILURE, FAILURE_MESSAGE, FAILURE_CODE);
	}
	public static OperationResult buildFailureResult(String message) {
		return new OperationResult(FAILURE, message, FAILURE_CODE);
	}
	public static OperationResult buildFailureResult(Object data) {
		return new OperationResult(FAILURE, FAILURE_MESSAGE, FAILURE_CODE,data);
	}
	public static OperationResult buildFailureResult(Integer code) {
		return new OperationResult(FAILURE, FAILURE_MESSAGE, code);
	}
	public static OperationResult buildFailureResult(String message,Integer code) {
		return new OperationResult(FAILURE, message, code);
	}
	public static OperationResult buildFailureResult(String message, Integer code,Object data) {
		return new OperationResult(FAILURE, message,FAILURE_CODE, data);
	}

}

